//
//  CWVisibleController.swift
//  CWWeibo06
//
//  Created by ycw on 2017/7/22.
//  Copyright © 2017年 xiaowei. All rights reserved.
//

import UIKit

class CWVisibleController: UITableViewController {

    var isLogin: Bool = CWUserAccountViewModel.userAccountViewModel.isLogin
    
    var visibleView: CWVisibleView?
    
    
    //自定义访客视图控制器
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    //重写loadview方法判断是否登录对view进行赋值
    override func loadView() {
        
        if isLogin {
            //登录成功
            super.loadView()
        }else{
            
            //没有登录
            setupNavigation()
            
            visibleView = CWVisibleView()
            
            visibleView?.loginCallBack = {[unowned self] in
                let oauthVC = CWOAuthController()
                
                let naviVC: CWNavigationController = CWNavigationController(rootViewController: oauthVC)
                
                self.present(naviVC, animated: true, completion: nil)
                
            }
            
            visibleView?.backgroundColor = UIColor(white: 237/255.0, alpha: 1)
            
            view = visibleView
        }
        
    }
    
    @objc private func setupNavigation() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(clickRegiestButton))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(clickLoginButton))
        
    }
    
    //MARK: 点击注册和登录按钮监听方法
    @objc private func clickRegiestButton() {
        
        let oauthVC = CWOAuthController()
        
        let naviVC: CWNavigationController = CWNavigationController(rootViewController: oauthVC)
        
        present(naviVC, animated: true, completion: nil)
        
    }
    
    @objc private func clickLoginButton() {
        
        let oauthVC = CWOAuthController()
        
        let naviVC: CWNavigationController = CWNavigationController(rootViewController: oauthVC)
        
        present(naviVC, animated: true, completion: nil)
    }

    

}
